﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Diagnostics;
using System.IO;
using System.Data.SqlClient;

/// <summary>
/// Summary description for VideoHelp
/// </summary>
public static class VideoHelp
{
public static  bool  changeVideoType(string fileName, string playFile, string imgFile)
{
//get the path of the video transformation tool
string ffmpeg= System.Web.HttpContext.Current.Server.MapPath("../");
//obtain the file path to transform
string Name = System.Web.HttpContext.Current.Server.MapPath("../") + fileName + "/" + fileName;
if ((!System.IO.File.Exists(ffmpeg)) || (!System.IO.File.Exists(Name)))
{
return false;
}             
//get the target path where to store the transformed file
string flv_file = playFile;
string widthOfFile = "";
string heightOfFile = "";
//create the instance of a process
Process pss = new Process();
//do not display the window
pss.StartInfo.CreateNoWindow = false;
// set up the path of the tool
pss.StartInfo.FileName = ffmpeg;
//specify the required arguments
pss.StartInfo.Arguments = " -i " + Name + " -ab 128 -ar 22050 -qscale 6 -r 29.97 -s " + widthOfFile + "x" + heightOfFile + " " + flv_file;
try
{
//start up the transform tool
pss.Start();
while (!pss.HasExited)
{
continue;
}
//capture the video related picture (see below)
catchImg(Name, imgFile);
System.Threading.Thread.Sleep(4000);
if (!File.Exists(imgFile))
{
File.Copy(System.Web.HttpContext.Current.Server.MapPath("../") + "imgHead\\default.gif", imgFile);
}
return true;
}
catch
{
return false;
}
}
    public static void catchImg(string fileName,string imgFile)
{
//get the screenshot capturing tool corresponding path
string ffmpeg = System.Web.HttpContext.Current.Server.MapPath("../");
//the path to hold the captured file
string flv_img = imgFile;
//capture size
string FlvImgSize = "";// sizeOfImg;
Process pss = new Process();    
//set up the path of the tool
pss.StartInfo.FileName = ffmpeg;      
pss.StartInfo.Arguments = "   -i   " + fileName + "  -y  -f  image2   -ss 2 -vframes 1  -s   " + FlvImgSize + "   " + flv_img;
//launch the tool related process
pss.Start();       
}  
public static string filtrateHtml(string str)
{
str = str.Trim();
str = str.Replace("'", "");
str = str.Replace("<", "<");
str = str.Replace(">", ">");
str = str.Replace(" ", " ");
str = str.Replace("\n", "<br>");
return str;
}
    public static string resumeHtml(string str)
{
str = str.Trim();
str = str.Replace("", "");
str = str.Replace("<", "<");
str = str.Replace(">", ">");
str = str.Replace(" ", " ");
str = str.Replace("<br>", "\n");
return str;
}
    public static string GetFlashText(string url)
{
url = "player.swf?fileName=" + url;
string str = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' width='452' height='360'  id='index' name='index'><param name='allowScriptAccess' value='always' /><param name='movie' value='" +
url + "'><embed src='" +
url + "' id='index1' name='index1' type='application/x-shockwave-flash' swLiveConnect=true allowScriptAccess='always' width='452' height='360'></embed></object>";
return str;
}
// public static  DataTable getRows(string sql)
//{
//DataSet ds;
//SqlConnection con = createCon();
//con.Open();
//SqlDataAdapter sda = new SqlDataAdapter(sql, con);
//ds = new DataSet();
//sda.Fill(ds);
//con.Close();
//return ds.Tables[0];
//}
  //public static   createCon()
  //  {

  //     string con ="";
  //     return con;
  //  }

}
